<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>cookie操作封装</title>
</head>
<body>
    <script>
        function setCookie(anme,value,expires){
            // 核心是操作字符串
            var cookie_str=name+"="+value;
            // 判断是不是要增加过期时间；
            if(typeof expires==="number"){
                var d=new Date();
                d.setDate(d.getDate()+expires);
                cookie_str+=";expires="+d;
                //  把拼接好的字符串设置到docunment.cookie上面
            }
            document.coolkie=cookie_str;
        }
        // 获取到cookie
        function getCookie(name){
            // 利用;加上一个空格的进行分割
            var cookire_arr=docunment.cookie.split("; ");
            for(var i=0;i<cookire_arr.length;i++){
                var cookie_item=cookie_arr[i];
                cookie_item=cookie_item.split("=");
                if(cookie_item[0]==name){
                return cookie_item[i];
            }

        }
        return "";

    }
    //    最后删除cookie;
    function removeCookie(name){
        setCookie(name, "",-1);
    }
    </script>
    
</body>
</html>